﻿using System;
using System.Web;
using Budget.Locator;
using Budget.Wcf.Core.AutoMapper;
using Castle.Core.Logging;

namespace Budget.Web
{
    public class Global : System.Web.HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            IoC.Init();

            AutoMapperConfiguration.Configure();
        }

        void Application_End(object sender, EventArgs e)
        {
            IoC.UnInit();
        }

        void Application_Error(object sender, EventArgs e)
        {
            var context = HttpContext.Current;
            var ex = context.Server.GetLastError();

            var logger = IoC.Locator.GetInstance<ILogger>();
            logger.Error(ex.Message);

            context.Server.ClearError();
        }
    }
}
